package day7.QuickHit;

import java.util.Scanner;

public class Player {
    private int levelNo=1; // 级别号
    private int curScore; // 当前积分
    private long startTime; // 各级别开始时间
    private int elapsedTime; // 各级别已用时间

    public int getLevelNo() {
        return levelNo;
    }

    public void setLevelNo(int levelNo) {
        this.levelNo = levelNo;
    }

    public int getCurScore() {
        return curScore;
    }

    public void setCurScore(int curScore) {
        this.curScore = curScore;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public int getElapsedTime() {
        return elapsedTime;
    }

    public void setElapsedTime(int elapsedTime) {
        this.elapsedTime = elapsedTime;
    }
    public void play() {
         Game game = new Game();
        Scanner input = new Scanner(System.in);
        for (int i = 0; i <Game.levels.length; i++) {
            this.levelNo = i+1;
            this.curScore = 0;
            for (int j = 0; j < Game.levels[levelNo-1].getStrTime(); j++) {
                this.startTime = System.currentTimeMillis();
                String outStr = game.printStr(Game.levels[levelNo-1].getStrLength());
                System.out.println(outStr);
                String inStr = input.next();
                game.printResult(outStr, inStr);
                if (game.printResult(outStr, inStr)==true){
                    long currentTime = System.currentTimeMillis();
                    if (((currentTime-getStartTime()) / 1000)
                            >Game.levels[getLevelNo() - 1].getTimeLimit()) {
                        System.out.println("你输入太慢了，已经超时，退出！");
                        System.exit(1);
                    } else {
                        setCurScore(getCurScore()
                                + Game.levels[levelNo - 1].getPerScore());
                        setElapsedTime((int) ((currentTime -getStartTime()) / 1000));
                        System.out.println("输入正确，您的级别"+levelNo+" ,您的积分" + getCurScore() + ",已用时间"	+ getElapsedTime() + "秒。");
                        if (getLevelNo() == 6) {
                            int score=Game.levels[levelNo - 1].getPerScore()
                                    *Game.levels[levelNo - 1].getStrTime();
                            if (getCurScore() == score) {
                                System.out.println("你已闯关成功，成为绝世高手，恭喜你！！！");
                                System.exit(0);
                            }
                        }
                    }
                }else {
                    System.out.println("输入错误，退出！");
                    System.exit(1);
                }
            }
        }
    }
}
